<!DOCTYPE html>

<head>
    <title>参与抽奖</title>
    <meta charset="utf-8" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta name="viewport" content="width=device-width, height=device-height, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
    <meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
    <meta http-equiv="Pragma" content="no-cache" />
    <meta http-equiv="Expires" content="0" />
    <link rel="stylesheet" href="https://res.wx.qq.com/open/libs/weui/2.4.1/weui.min.css" />
	<script src="http://code.jquery.com/jquery-2.1.1.min.js"></script>
    <script src="https://res.wx.qq.com/open/js/jweixin-1.6.0.js"></script>
</head>
<body>
<div id="wechat-web-container" style="width: 100%;height: 100vh;display: flex; align-items: center;justify-content: center">
    <wx-open-launch-weapp id="launch-btn" username="gh_205c1dc88518" path="packageB/activity/activityAlliance/activityAlliance?id=3539965176&sc=2246756995">
        <template>
            <button id="toWxapp" style="font-size: 20px;background: #00BC0C;color: #fff;border: 0;border-radius: 5px;width:340px;height:45px;line-height:45px;text-align:center;">我要抽奖(100%可领取)</button>
        </template>
    </wx-open-launch-weapp>
</div>
<script type="text/javascript">
$(document).ready(function() {
	$.ajax({
		url: 'http://newsales.chinaesf.net/yl/wechat/getJSSdk',
		success: function(res){
			console.log("getJSSdk=", res);
			if (res.code === 1000) {
				var config = res.data;
				wx.config({
					debug: false,
					appId: config.appId,
					timestamp: config.timestamp,
					nonceStr: config.nonceStr,
					signature: config.signature,
					jsApiList: ['chooseImage', 'previewImage'],
					openTagList:['wx-open-launch-weapp']
				});
				wx.ready(function () {
					var btn = document.getElementById('launch-btn');
					btn.addEventListener('launch', function (e) {
						console.log('success');
						// alert('success')
						toWxapp();
					});
					btn.addEventListener('error', function (e) {
						console.log('fail', e.detail);
						alert('fail='+e.detail);
						// alert('fail', e.detail)
					});
				});
			} else {
				alert("请求失败，请稍后再试！");
			}
		},
		error: function (err) {
			alert("网络繁忙，请稍后再试！");
		}
	})
});
function toWxapp(){
    console.log("跳转到指定小程序");
	document.getElementById("toWxapp").onclick();
};
</script>
</body>
</html>